package org.jpush.core.stats;

public class CumulMeasure extends Measure
{
	private boolean blnIsContinous;
	private double cumulValue;

	public CumulMeasure(String name)
	{
		this(name, false);
	}

	public CumulMeasure(String name, boolean bIsContinous)
	{
		super(name);
	    this.blnIsContinous = bIsContinous;
	    this.cumulValue = 0;
	}

	public void addObservation(MeasureArgs args)
	{
	    if (!(args instanceof CumulMeasureArgs))
	    	return;

	    CumulMeasureArgs myArgs = (CumulMeasureArgs) args;
	    cumulValue += myArgs.value;
	}

	public String collectAndReset(String timeStamp)
	{
	    //Collect
		StringBuffer sb = new StringBuffer();

		sb.append("<").append(name).append(" val=\"").append(cumulValue).append("\"/>");

	    //Reset to zero if not continuous.
	    if (!blnIsContinous)
	        cumulValue = 0;
	    //
	    return sb.toString();
	}

}
